e560f8ec546aaa48d731543e7a03aa244b93619e,opennms-tools/mib2events/src/main/java/org/opennms/netmgt/mib2events/Mib2Events.java,Mib2Events,printEvents,#Mib#String#,314
Before Change
}
public static void printEvents(Mib mib, String ueibase) {
Collection syms = mib.getAllSymbols();
Iterator<MibSymbol> symIter = syms.iterator();
MibSymbol sym = null;
MibValueSymbol vsym = null;
Iterator<MibValue> trapVarbinds;
Events events = new Events();
StringWriter writer = new StringWriter();
while (symIter.hasNext()) {
sym = symIter.next();
if (! (sym instanceof MibValueSymbol))
continue;
vsym = (MibValueSymbol)sym;
if ((! (vsym.getType() instanceof SnmpNotificationType)) && (! (vsym.getType() instanceof SnmpTrapType)))
continue;
events.addEvent(getTrapEvent(vsym, ueibase));
}
if (events.getEventCount() < 1) {
System.err.println("No trap definitions found in this MIB (" + mib.getName() + "), exiting");
System.exit(0);
}
try {
events.marshal(writer);
prettyPrintXML(new ByteArrayInputStream(writer.toString().getBytes()), (OutputStream)System.out);
} catch (MarshalException e) {
System.err.println("Fatal: caught MarshalException:" + e);
} catch (ValidationException e) {
After Change
}
}
private void printEvents(PrintStream out) {
if (m_loader == null) {
throw new IllegalStateException("convert() must be called first");
}
for (Mib mib : m_loader.getAllMibs()) {
if (!mib.isLoaded()) {
continue;
}
Events events = convertMibToEvents(mib, m_ueiBase);
if (events.getEventCount() < 1) {
System.err.println("No trap definitions found in this MIB (" + mib.getName() + "), exiting");
System.exit(0);
}
try {
// FIXME We should just spit out a valid events inclusion file, but for now we match mib2opennms
//StringWriter writer = new StringWriter();
//
//events.marshal(writer);
//
//String noNameSpace = writer.toString().replaceAll(" xmlns=\"[^\"]*\"", "");
//prettyPrintXML(new ByteArrayInputStream(noNameSpace.getBytes()), out);
for (Event event : events.getEventCollection()) {
StringWriter writer = new StringWriter();
event.marshal(writer);
String noNameSpace = writer.toString().replaceAll(" xmlns=\"[^\"]*\"", "");
ByteArrayOutputStream formattedXml = new ByteArrayOutputStream();
prettyPrintXML(new ByteArrayInputStream(noNameSpace.getBytes()), formattedXml);
String noXmlProcessingInstruction = formattedXml.toString().replaceAll("(?m)<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n", "");
String singleQuotesLogMsgDest = noXmlProcessingInstruction.replaceAll("dest=\"logndisplay\"", "dest='logndisplay'");
out.print(singleQuotesLogMsgDest);
}
} catch (MarshalException e) {
System.err.println("Fatal: caught MarshalException:" + e);